namespace ado_net_by_example
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
/// <summary>
/// Summary description for StoredProc.
/// </summary>
public class StoredProc : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
public StoredProc()
{
Page.Init += new System.EventHandler(Page_Init);
}
protected void Page_Load(object sender, EventArgs e)
{
// Connect to the Database
SqlConnection cn = new SqlConnection(ConfigurationSettings.AppSettings["pubs"]);
cn.Open();
// Create a command object
System.Data.SqlClient.SqlCommand cmd =
new System.Data.SqlClient.SqlCommand();
cmd.Connection = cn;
// Set CommandText to the name of the
// stored procedure
cmd.CommandText = "AuthorCount";
// Indicate that we're calling a stored proc
cmd.CommandType = CommandType.StoredProcedure;
// Add parameters to the command object that
// mirror the actual parameters of the stored
// procedure
SqlParameter TempParam;
TempParam = new SqlParameter(
"@state",SqlDbType.VarChar,2);
// For input paramteres, supply a value
TempParam.Value = "CA";
cmd.Parameters.Add(TempParam);
TempParam = new SqlParameter(
"@count", SqlDbType.Int);
// For output parameters, specift the direction.
// If we don't specify a direction, it will default
// to input.
TempParam.Direction = ParameterDirection.Output;
cmd.Parameters.Add(TempParam);
// Execute the proc
cmd.ExecuteNonQuery();
// Retrieve the data from the output paramter
// and display it on the page.
Label1.Text = cmd.Parameters["@count"].Value.ToString();
}
protected void Page_Init(object sender, EventArgs e)
{
//
// CODEGEN: This call is required by the ASP+ Windows Form Designer.
//
InitializeComponent();
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler (this.Page_Load);
}
}
}